package chapter_21_observer.mytest;


import java.util.Observable;

/**
 * Created by yao on 2016/11/18.
 * 被观察者类
 * Observable是被观察者接口
 * 被观察者类有状态更新，要提示观察者类
 */
public class Watched extends Observable {

    private int age = 1;

    private Watcher watcher;

    public int getAge(){
        return age;
    }

    public Watched(Watcher watcher) {
        this.watcher = watcher;
        super.addObserver(watcher);
    }

    public void changeAge(int age){
        if(this.age == age){

        }else{
            this.age = age;
            super.setChanged();
            super.notifyObservers();
        }
    }


}
